import { SUBMIT,GET,INIT_SCHOOLS,INIT_NEWS } from './actionTypes';
const defaultState={
    user:'',
    pwd:'',
    schools:[],
    news:[]
}

export default (state = defaultState,action)=>{
    if(action.type===SUBMIT){
        const newState = JSON.parse(JSON.stringify(state));
        newState.user=action.value.username;
        newState.pwd=action.value.pwd;
        return newState;
    }

    if(action.type===GET){
        const newState = JSON.parse(JSON.stringify(state));
        newState.user = localStorage.getItem('user');
        newState.pwd = localStorage.getItem('pwd');
        return newState;
    }

    if(action.type===INIT_SCHOOLS){
        const newState = JSON.parse(JSON.stringify(state));
        newState.schools=action.data;
        return newState;
    }

    if(action.type===INIT_NEWS){
        const newState = JSON.parse(JSON.stringify(state));
        newState.news=action.data;
        return newState;
    }

    return state;
}